﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Collections;
using Microsoft.ApplicationBlocks.Data;
using System.IO;
//using Microsoft.Office.Interop.Word;
//using Word = Microsoft.Office.Interop.Word;//2007
using System.Diagnostics;
using System.Threading;

using System.Runtime.InteropServices; //引用

namespace kxjsj
{
    class SysFunClass
    {


        #region 设置richtextbox行距
        private const int WM_USER = 0x0400;
        private const int EM_GETPARAFORMAT = WM_USER + 61;
        private const int EM_SETPARAFORMAT = WM_USER + 71;
        private const long MAX_TAB_STOPS = 32;
        private const uint PFM_LINESPACING = 0x00000100;
        [StructLayout(LayoutKind.Sequential)]
        private struct PARAFORMAT2
        {
            public int cbSize;
            public uint dwMask;
            public short wNumbering;
            public short wReserved;
            public int dxStartIndent;
            public int dxRightIndent;
            public int dxOffset;
            public short wAlignment;
            public short cTabCount;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] rgxTabs;
            public int dySpaceBefore;
            public int dySpaceAfter;
            public int dyLineSpacing;
            public short sStyle;
            public byte bLineSpacingRule;
            public byte bOutlineLevel;
            public short wShadingWeight;
            public short wShadingStyle;
            public short wNumberingStart;
            public short wNumberingStyle;
            public short wNumberingTab;
            public short wBorderSpace;
            public short wBorderWidth;
            public short wBorders;
        }

        [DllImport("user32", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref PARAFORMAT2 lParam);

        public static void SetLineSpace(Control ctl, int dyLineSpacing)
        {
            PARAFORMAT2 fmt = new PARAFORMAT2();
            fmt.cbSize = Marshal.SizeOf(fmt);
            fmt.bLineSpacingRule = 4;// bLineSpacingRule;
            fmt.dyLineSpacing = dyLineSpacing * 30;
            fmt.dwMask = PFM_LINESPACING;
            try
            {
                SendMessage(new HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT, 0, ref fmt);
            }
            catch
            {

            }
        }
        #endregion


        //public Image ResizePic(Image oldImg, int ThumbnailImageWidth, int ThumbnailImageHeight)
        //{
        //    Image thumnailImg = oldImg.GetThumbnailImage(ThumbnailImageWidth, ThumbnailImageHeight, new Image.GetThumbnailImageAbort(CallBack), IntPtr.Zero);
        //    ImageCodecInfo imgCodeInfo = GetImageCodeInfo("image/gif");
        //    if (imgCodeInfo != null)
        //    {
        //        EncoderParameters encodeParameters = new EncoderParameters(1);
        //        encodeParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);
        //        Bitmap bmp = new Bitmap(thumnailImg);
        //        encodeParameters.Dispose();
        //        encodeParameters = null;
        //        return bmp;
        //        //bmp.Save(@"c:\result.jpg", imgCodeInfo, encodeParameters);
        //    }
        //    return null;
        //}
        //public void image500k(long img_size,long max_size, OpenFileDialog d, TextBox accessory_f4)
        //{
        //    if (img_size > max_size)
        //    {
        //        Bitmap bmp = new Bitmap(d.FileName);
        //        Bitmap tmp = null;
        //        {
        //            tmp = new Bitmap(bmp);
        //        }
        //        bmp.Dispose();
        //        Size s = tmp.Size;
        //        Bitmap b = null;
        //        if (s.Width < s.Height && s.Width > 800 && s.Height > 1200)
        //        {
        //            b = helper.KiResizeImage(tmp, 800, s.Height * 800 / s.Width, 0);
        //            tmp.Dispose();
        //        }
        //        else if (s.Width > s.Height && s.Width > 1200 && s.Height > 800)
        //        {
        //            b = helper.KiResizeImage(tmp, s.Width * 800 / s.Height, 800, 0);
        //            tmp.Dispose();
        //        }
        //        else
        //        {
        //            b = tmp;
        //        }
        //        GC.Collect();
        //        string fn = System.Windows.Forms.Application.StartupPath + "\\tmp\\" + DateTime.Now.ToFileTime().ToString() + ".jpg";
        //        b.Save(fn, System.Drawing.Imaging.ImageFormat.Jpeg);
        //        b.Dispose();
        //        accessory_f4.Text = fn;
        //        MessageBox.Show("图片大于500KB，已自动压缩。您也可以手动压缩，请确保正向。", "提示");
        //    }
        //}
        //static public void InsertPageNumber(Microsoft.Office.Interop.Word.Application wordApp, string strType, bool bHeader)//Word._Application->Word.Application
        //{
        //    try
        //    {
        //        //wordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
        //        object oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;//Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
        //        object oFirstPage = bHeader;
        //        //Microsoft.Office.Interop.Word.WdHeaderFooterIndex WdFooterIndex = Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary;

        //        switch (strType)
        //        {
        //            case "Center":
        //                oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
        //                //oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
        //                break;

        //            case "Right":
        //                oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberRight;
        //                //Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberRight;
        //                break;

        //            case "Left":
        //                oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
        //                //Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
        //                break;
        //        }
        //        wordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;

        //        //wordApp.Selection.Fields.Add 
        //        //wordApp.Selection.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref oAlignment, ref oFirstPage);
        //        //wordApp.Selection.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.NumberStyle =Word.WdPageNumberStyle.wdPageNumberStyleTradChinNum1; 

        //        //wordApp.Selection.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref oAlignment, ref oFirstPage);
        //        //wordApp.Selection.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.NumberStyle =
        //        //Microsoft.Office.Interop.Word.WdPageNumberStyle.wdPageNumberStyleTradChinNum1;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}


    }
}
